package cn.alcatraz.basic.service.impl;

import cn.alcatraz.basic.mapper.BaseMapper;
import cn.alcatraz.basic.query.BaseQuery;
import cn.alcatraz.basic.service.IBaseService;
import cn.alcatraz.basic.utils.PageList;

import cn.alcatraz.basic.query.BaseQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    BaseMapper<T> baseMapper;
    
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);

    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {

        // 查询分页总条数
        Integer total = baseMapper.queryCount(baseQuery);
        List<T> rows = baseMapper.queryData(baseQuery);

        return new PageList<>(total, rows);
    }

    @Override
    public void batchDelete(Long[] ids) {
        baseMapper.batchDelete(ids);
    }

}
